﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using omsData;
namespace myomscl_web.Admin.UserControls
{
    public partial class ucEditOrganization : System.Web.UI.UserControl
    {
        public string OrganizationId { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadOrganization();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (OmsModelContainer context = new OmsModelContainer())
            {
                var org = context.Organisations.Where(o => o.Id.ToString() == OrganizationId).First();
                org.Name = txtOrganizationName.Text;
                org.City = txtCity.Text;
                org.Address = txtAddress.Text;
                org.Phone1 = txtPhone1.Text;
                org.Phone2 = txtPhone2.Text;
                org.Email = txtEmail.Text;

                context.SaveChanges();
                EditOrganization(txtOrganizationName.Text);
            }
        }

        public void LoadOrganization()
        {
            using (OmsModelContainer context = new OmsModelContainer())
            {
                var org = context.Organisations.Where(o => o.Id.ToString() == OrganizationId).First();
                this.txtOrganizationName.Text = org.Name;
                this.txtCity.Text = org.City;
                this.txtAddress.Text = org.Address;
                this.txtPhone1.Text = org.Phone1;
                this.txtPhone2.Text = org.Phone2;
                this.txtEmail.Text = org.Email;
            }
        }



        public delegate void OnEditOrganization(string organizationName);
        public event OnEditOrganization EditOrganization;
    }
}